package com.senriot.quickup.web.rest

import com.querydsl.core.types.Predicate
import com.senriot.cloud.common.AbstractController
import com.senriot.cloud.common.annotation.EntityName
import com.senriot.quickup.domain.Ad
import com.senriot.quickup.domain.AdSchedule
import com.senriot.quickup.domain.QAdSchedule
import com.senriot.quickup.service.AdScheduleService
import com.senriot.quickup.service.dto.AdDTO
import com.senriot.quickup.service.dto.AdScheduleDTO
import io.swagger.annotations.ApiOperation
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Sort
import org.springframework.data.querydsl.binding.QuerydslPredicate
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.servlet.ModelAndView
import java.time.LocalDateTime

@RestController
@RequestMapping("/api/adSchedule")
@EntityName("adSchedule")
class AdScheduleResource :AbstractController<AdSchedule, Long, AdScheduleDTO, AdScheduleService>()
{
    override fun loadAll(sort: Sort, @QuerydslPredicate(root = AdSchedule::class) predicate: Predicate?): List<AdScheduleDTO> {
        return super.loadAll(sort, predicate)
    }

    override fun loadPage(page: Pageable, @QuerydslPredicate(root = AdSchedule::class) predicate: Predicate?): Page<AdScheduleDTO> {
        return super.loadPage(page, predicate)
    }

    override fun count(@QuerydslPredicate(root = AdSchedule::class) predicate: Predicate?): ResponseEntity<Long> {
        return super.count(predicate)
    }

    override fun exportXls(predicate: Predicate?): ModelAndView
    {
        return super.exportXls(predicate)
    }

    /**
     * 获取设备广告
     * @param deviceId String 设备名称
     * @return MutableIterable<AdSchedule>
     */
    @GetMapping("/device/{deviceId}")
    @ApiOperation("获取设备广告")
    fun getAdByDevice(@PathVariable deviceId: String): MutableList<Ad>
    {
       return service.getAdByDevice(deviceId)
    }
}
